package com.privatbank.servlets;

import com.privatbank.DTO.GoodDTO;

import com.privatbank.constants.Constants;
import com.privatbank.tables.Good;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created by Slava on 03.08.2014.
 */
public class DtoServlet extends HttpServlet {
    private GoodDTO dto = null;

    @Override
    public void init() {
        dto = new GoodDTO(Constants.LOGIN, Constants.PASSWORD, Constants.URL);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        init();
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter pw = resp.getWriter();
        pw.println("<B>Successful JOIN </B>");
        pw.println("<table border=1>");
        try {
            pw.println("<tr>");
            pw.println("<th>Model</th>");
            pw.println("<th>category</th>");
            pw.println("<th>manufacturer</th>");
            pw.println("</tr>");
            List<GoodDTO> l = dto.fullGood();
            for (GoodDTO good : l) {
                pw.println("<tr>");
                pw.println("<td>" + good.getModel() + "</td>");
                pw.println("<td>" + good.getManufacturer() + "</td>");
                pw.println("<td>" + good.getCategory() + "</td>");
                pw.println("</tr>");
            }
        } catch (Exception e) {
            throw new ServletException(e);
        }
        pw.println("</table>");
        {

        }
    }
}